package at.fhj.itm;



/**
 * 
 * @author Eduardo da Silva
 * @version 1.0.0
 */

/**
 * class Queue first in first out 
 */
public class Queue {
	
  private int maxSize;

  private long[] queArray;

  private int front;

  private int rear;

  private int nItems;

  public Queue(int s) {
    maxSize = s;
    queArray = new long[maxSize];
    front = 0;
    rear = -1;
    nItems = 0;
  }

  
  /**
   * put item at end of a queue
   * @param j adds j to the rear of array
   */
  public void insert(long j) {
    if (rear == maxSize - 1) // deal with wraparound
      rear = -1;
    queArray[++rear] = j; // increment rear and insert
    nItems++; 
  }

  /**
   * take item from front of queue  
   * @return 
   */
  public long remove() {
    long temp = queArray[front++]; // get value and incr front
    if (front == maxSize) // deal with wraparound
      front = 0;
    nItems--; // one less item
    return temp;
  }

  /**
   * 
   * @return first element
   */
  public long peekFront() {
    return queArray[front];
  }

  /**
   * 
   * @return true if array is empty else false
   */
  public boolean isEmpty() {
    return (nItems == 0);
  }
  
  /**
   * 
   * @return true if array is full else false
   */
  public boolean isFull() {
    return (nItems == maxSize);
  }
  
  /**
   * 
   * @return actual size of array
   */
  public int size() {
    return nItems;
  }
  
}
           
         